package mymyoux.lang
{
	import flash.text.TextField;
	import flash.utils.flash_proxy;
	
	import mymyoux.signals.Signal;
	import mymyoux.utils.DoubleHash;
	

	public class I18n
	{
		protected var _lang:DoubleHash;
		protected var _default:String;
		public function I18n()
		{
			_default = "default";
			_lang = new DoubleHash();			
		}
		public function getSignal(categorie:String = ""):Signal
		{
			if(categorie == null || categorie.length == 0)
			{
				categorie = _default;
			}
			return _lang.get(categorie).signal;
		}
		public function get(key:String):String
		{
			var cat:String = _default;
			var id:int = key.indexOf("/");
			if(id == -1)
			{
				id = key.indexOf(":");
			}
			if(id > -1)
			{
					cat = key.substring(0, id);
					key = key.substring(id + 1);
			}
			var trad:String = _lang.get(cat).get(key);
			if(trad == null)
			{
				return "";
			}
			return trad+"";
		}
		public function set(key:String,  value:String):void
		{
			var cat:String = _default;
			var id:int = key.indexOf("/");
			if(id == -1)
			{
				id = key.indexOf(":");
			}
			if(id > -1)
			{
				cat = key.substring(0, id);
				key = key.substring(id + 1);
			}
			_lang.get(cat).set(key, value);
		}
	}
}